package com.tdkj.action.backstage.decorate;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.tdkj.action.BaseAction;
import com.tdkj.model.decorate.BeanLayout;
import com.tdkj.model.decorate.BeanStyle;
import com.tdkj.service.decorate.IBeanLayoutService;


public class LayoutAction extends BaseAction {
    
	private IBeanLayoutService layoutService;
	
	private List<BeanLayout> layouts ;
	
	private BeanLayout layout ;
	
	public String execute() {
		layouts = layoutService.findAll(BeanLayout.class);
		String hql = "from " + BeanLayout.class.getName() + " as bean where bean.parent is null";
		Query query = this.createQuery(hql);
		this.queryByPage(query, "layoutAction.action", 10);
		return "success";
	}
	
	public String add() {
		layoutService.save(layout);
		return execute();
	}
	
	public String update() {
		layoutService.saveOrUpdate(layout, BeanLayout.class);
		return execute();
	}

	public String delete() {
		layoutService.delete(layout.getId(),BeanLayout.class);
		return execute();
	}
	
	public String edit() {
		layout = layoutService.findById(layout.getId(), BeanLayout.class);
		return "edit";
	}

	public List<BeanLayout> getLayouts() {
		return layouts;
	}

	public void setLayouts(List<BeanLayout> layouts) {
		this.layouts = layouts;
	}

	public BeanLayout getLayout() {
		return layout;
	}

	public void setLayout(BeanLayout layout) {
		this.layout = layout;
	}

	@Resource
	public void setLayoutService(IBeanLayoutService layoutService) {
		this.layoutService = layoutService;
	}
	
	
	
}
